package ru.rchervot.sanasar.client.view;

import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;

public abstract class AbstractContentView extends Composite implements ContentPresenter.Display, ResizeHandler {
	
	protected VerticalPanel basePanel = new VerticalPanel();
	
	private ContentPresenter presenter;
	
	public AbstractContentView() {
		super();
		
		basePanel.setSize("100%", "100%");
		this.initWidget(basePanel);
		
		Window.addResizeHandler(this);
		DeferredCommand.addCommand(new Command() {
			public void execute() {
				onWindowResized(Window.getClientWidth(), Window.getClientHeight());
			}
		});
	}
	
	@Override
	public void setPresenter(ContentPresenter presenter) {
		this.presenter = presenter;
	}
	
	public abstract void onWindowResized(int width, int height);
	
	@Override
	public void onResize(ResizeEvent event) {
		onWindowResized(Window.getClientWidth(), Window.getClientHeight());
	}
	
	
}
